package main

import (
	"flag"
	"fmt"
	"net/http"
)

// 配置文件路径
var configFile *string

// 配置文件
var configMap map[string]map[string]string

// token 信息
var accessToken Token

func init() {

	configFile = flag.String("config", "alertConfig.json", "配置文件")
	flag.Parse()
	err := loadConfig(*configFile)
	if err != nil {
		fmt.Printf("加载配置出错%s", err)
	}
}

func main() {

	// fmt.Println(*configFile)
	// fmt.Println(configMap)
	http.HandleFunc("/qywechat", qyWechatHandler)
	http.HandleFunc("/email", emailHandler)
	http.HandleFunc("/appalert", appMonitorHandler)
	http.HandleFunc("/", alertHandler)
	// fmt.Printf(fmt.Sprintf("%s:%s", configMap["globals"]["bind"], configMap["globals"]["port"]))
	err := http.ListenAndServe(fmt.Sprintf("%s:%s", configMap["globals"]["bind"], configMap["globals"]["port"]), nil)
	if err != nil {
		fmt.Printf("程序启动监听端口失败:%s", err)
	}
}
